package edu.fdzc.big_event.controller;

import edu.fdzc.big_event.pojo.Result;
import edu.fdzc.big_event.service.MinioService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@RestController
public class FileController {

    @Autowired
    private MinioService minioService;

    @PostMapping("/upload")
    public Result<String> upload(MultipartFile file) {
        try {
            String objectName = minioService.uploadFile(file);
            String url = minioService.getFileUrl(objectName);
            log.info("url:{}", url);
            log.info("url长度{}",url.length());
            return Result.success(url);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}
